<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!-- 增加学期计划的时候，直接在创建时间时，增加标签 -->
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
 <!-- 增加用户开始 -->
<div id="dialog-message_class">
		<div id="learnPlantAdd_buzhou"> 
		 		<table>
		 		    <tr>
		 				<td>名称</td>
		 				<td><input type="text" id="buzhou1"  name="buzhou1" require='true' meth="notNull" title="不能为空" name="name" maxlength="20"></td>
		 			</tr>
		 			<tr>
		 				<td>时长分钟</td>
		 				<td><input type="text"  id="buzhou2" name="buzhou2"   require='true' meth="notNull,isNumber" title="时长只能输入数字" maxlength="2" title="只能输入数字类型"></td>
		 			</tr>
		 			<tr>
		 				<td>场地</td>
		 				<td><input type="text"  id="buzhou3" name="buzhou3" maxlength="20"></td>
		 			</tr>
		 			<tr>
		 				<td>内容</td>
		 				<td><input type="text"  id="buzhou5" name="buzhou5" maxlength="50"></td>
		 			</tr>
		 			<tr>
		 				<td>教学器材</td>
		 				<td><input type="text" id="buzhou6" name="buzhou6" maxlength="30"></td>
		 			</tr> 
		 			<tr>
		 				<td>附件</td>
		 				<td><input type="text"  id="buzhou4" name="buzhou4" maxlength="20"></td>
		 			</tr>
		 			<tr>
		 				<td>步骤所需标签</td>
		 				<td id="buzhoubiaoqian">
		 					
		 					
		 				</td>
		 			</tr> 
		 		</table> 
		</div>
									 
</div>
<!-- 增加用户结束-->
<script>
(function(){  
	var id1 ="${param.id1}"; 
	//加载当前模块下的所有标签
	function load(){ 
		  var url ="${pageContext.request.contextPath}/edu/sys_LearnPlantAction.do?method=getAllLableByPltype1";
			 $.ajax({
			   type: "POST",
			   url: url,	
			   data:{id1:id1},
			   dataType:"json",
			   success: function(msg){
				 if(msg.list){
					for(var i=0;i<msg.list.length;i++){
						var vt='<input type="checkbox" name="checklable" table_id ="'+msg.list[i].table_id+'" text="'+msg.list[i].name+'">'+msg.list[i].name;
						$("#buzhoubiaoqian").append(vt); 
					} 
					//将上一个页面的增加的标签拿过来
					var lablebuton = $("button[name=lablebuton]");
					for(var i=0;i<lablebuton.length;i++){
						var b =false;
						for(var j=0;j<msg.list.length;j++){
							if($(lablebuton[i]).attr("table_id") == msg.list[j].table_id){
								b=true;
								break;
							}
						}
						if(b==false){
							var vt='<input type="checkbox" name="checklable" table_id ="'+$(lablebuton[i]).attr("table_id")+'" text="'+$(lablebuton[i]).text()+'">'+$(lablebuton[i]).text();
							$("#buzhoubiaoqian").append(vt); 
						}
					}
				 }
			   }
			});  
	};
	
	//增加步骤
	function addbuZhou(contrl){
		
		var a =$("#learnPlantAdd_buzhou").hzValidate("init");  
		if(a==false){
			return;
		}else{
			var object = OAajaxSubmit("learnPlantAdd_buzhou"); 
			var checklable =$("input[type=checkbox]");
			var arr = new Array();
			var vt="";
			for(var i=0;i<checklable.length;i++){
				if(checklable[i].checked==true){
					var object1 = new Object();
					object1.table_id = $(checklable[i]).attr("table_id");
					object1.text =$(checklable[i]).attr("text");
					arr.push(object1);
				} 
			}
			for(var i=0;i<arr.length;i++){
				if(i==arr.length-1){
					vt+='<button class="btn btn-xs btn-inverse" style="margin-top:4px;" name="lablebuton1" table_id="'+arr[i].table_id+'">'+arr[i].text+'<i class="icon-remove"></i></button>';
					 
				}else{
					vt+='<button class="btn btn-xs btn-inverse" style="margin-top:4px;" name="lablebuton1" table_id="'+arr[i].table_id+'">'+arr[i].text+'<i class="icon-remove"></i></button>&nbsp;';
				}
			}
			object.arrlable=arr;			
			var tr ='<tr name="buzhoutr">'+
	 			'<td>'+object.buzhou1+'</td>'+
	 			'<td>'+object.buzhou2+'</td>'+
	 			'<td>'+object.buzhou5+'</td>'+
	 			'<td>'+object.buzhou4+'</td>'+
	 			'<td>'+vt+'</td>'+
	 			'<td>'+object.buzhou3+'</td>'+
	 			'<td>'+object.buzhou6+'</td>'+
	 			'<td><button class="btn btn-xs" name="btndelete">删除</button></td>'+
	 			'</tr>';
			if($("#childrenLv5").length>0){
				 var  tr1 =$(tr);
				 tr1.data("pl",object); 
				 $("#childrenLv5").append(tr1); 
			}
			$(contrl).dialog('destroy'); 
			$("#learnPlantAdd_ClassWindow").html("");
			$("button[name=lablebuton1]").unbind().click(function(){
				var data =$(this).parent().parent().data("pl");
				if(data && data.arrlable && data.arrlable.length>0){
					var arr = new Array();
					for(var i=0;i<data.arrlable.length;i++){
						if(data.arrlable[i].table_id != $(this).attr("table_id")){
							arr.push(data.arrlable[i]);
						}
					}
					data.arrlable =arr;
					$(this).parent().parent().data("pl",data);
				} 
				$(this).remove(); 
			});
			$("button[name=btndelete]").click(function(){
				
				$(this).parent().parent().remove();
			});
		} 
	};
	
	$(function(){
		if(id1!=""){
			load();
		}
	});
	window.learnPlantAdd_Lable_buzhou={};
	window.learnPlantAdd_Lable_buzhou.addbuZhou=addbuZhou;
})();
</script>
